<template>

            <el-container class="home">
                <el-aside width="200px" >
                    <el-menu router unique-opened>
                      <br><br>
                      <span class="a">&emsp;人事管理系统</span>
                      <br><br>
                        <el-submenu :index="index+''" v-for="(item,index) in $router.options.routes" v-if="!item.hidden" :key="index">
                            <template slot="title">

                                <i class="el-icon-collection-tag"></i>
                                <span class="el-menu-font">{{item.name}}</span>
                            </template>

                            <el-menu-item :index="child.path" v-for="(child,indexj) in item.children" :key="indexj">

                              <span class="el-submenu-font">{{child.name}}</span>
                            </el-menu-item>
                        </el-submenu>
                    </el-menu>
                </el-aside>
                <el-main>
                  <div class="c">
                    <el-container   style="float: right">
                      <span></span>

                                            <div>
                                              <el-dropdown class="userInfo" @command="commandHandler">
                                             <span class="el-dropdown-link">
                                            <b><i class="el-icon-s-custom"></i></b>
                                             <i></i>
                                             </span>
                                                <el-dropdown-menu slot="dropdown">

                                                  <!--                            <el-dropdown-item command="setting">设置</el-dropdown-item>-->
                                                  <el-dropdown-item command="logout" >退出登录</el-dropdown-item>
                                                </el-dropdown-menu>
                                              </el-dropdown>
                                            </div>

                    </el-container>

                    <br>
                  </div> <hr><br>
                    <el-breadcrumb separator-class="el-icon-arrow-right" v-if="this.$router.currentRoute.path!='/home'">
                        <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
                        <el-breadcrumb-item>{{this.$router.currentRoute.name}}</el-breadcrumb-item>
                    </el-breadcrumb>

                    <router-view class="homeRouterView"/>
                </el-main>
            </el-container>

</template>

<script>
    export default {
        name: "Home",
        data() {
            return {
                // user: JSON.parse(window.sessionStorage.getItem("user"))
            }
        },
        computed: {
            routes() {
              console.log("查找的routes = ", this.$store.state.routes)
                return this.$store.state.routes;
            },
            user() {
                return this.$store.state.currentHr;
            },
            userId() {
              // var currentId = localStorage.getItem('id');
              var currentId = localStorage.getItem("id");
              console.log("currentId = ", localStorage.getItem("id"));
              console.log("type = ", localStorage.getItem("type"));
              return currentId;
            },
            userRole() {
              var result = '';
              // console.log("登陆的员工角色：", role);
              // if (role === '总裁') {
              //   result = "总裁";
              // } else if (role === '主管') {
              //   result = "主管";
              // } else {
              //   result = "员工";
              // }
              return localStorage.getItem("role");
            }
        },
        methods: {
            goChat() {
                this.$router.push("/chat");
            },
            commandHandler(cmd) {
                if (cmd == 'logout') {
                    this.$confirm('此操作将注销登录, 是否继续?', '提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning'
                    }).then(() => {
                        // this.getRequest("/logout");
                        window.sessionStorage.removeItem("user")
                        this.$store.commit('initRoutes', []);
                        this.$router.replace("/");
                    }).catch(() => {
                        this.$message({
                            type: 'info',
                            message: '已取消操作'
                        });
                    });
                }else if (cmd == 'userinfo') {
                    this.$router.push('/hrinfo');
                }
            },
        }
    }
</script>

<style>
    .home{
      height: 100vh
    }
    *{
      /*height: 100vh;*/
      margin: 0;
      padding: 0;
    }
    .homeRouterView {
        margin-top: 10px;
    }
    .el-menu{
      height: 100%;
      background-color: #19422e;
    }
    .a{
      padding-top: 30px;
      font-size: 25px;
      font-family: 华文彩云;
      color: #eaeaea;
    }
    .b{
      padding-top: 30px;
      margin: 0;
      width: 150px;
      height: 35px;
    }
    .c{
      width: 1170px;
    }

    .el-main{

    }
    .homeWelcome {
        text-align: center;
        font-size: 30px;
        font-family: 华文行楷;
        color: #409eff;
        padding-top: 50px;
    }

    .homeHeader {
        background-color: #006000;
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 0px 15px;
        box-sizing: border-box;
    }

    .homeHeader .title {
        font-size: 40px;
        font-family: 华文行楷;
        color:floralwhite;
    }

    .homeHeader .userInfo {
        cursor: pointer;
    }

    .el-dropdown-link img {
        width: 48px;
        height: 48px;
        border-radius: 24px;
        margin-left: 8px;
    }

    .el-dropdown-link {
        display: flex;
        align-items: center;
    }
    .el-menu-font {
      color: #eaeaea;
      font-family: 方正姚体;
    }
    .el-submenu-font {
      color: #eaeaea;
      font-family: 华文楷体;
    }
</style>